/*
 * GoldViewMenuItem.cpp
 *
 *  Created on: 2015-9-18
 *      Author: 10095427
 */

#include "GoldViewMenuItem.h"
USING_NS_CC;

#define WIDTH   160
#define HEIGHT  140
#define TEXT_TAG 10
#define TEXT_Y   15
#define TEXT_FONT_SIZE  22
#define TEXT_FONT_NAME  "arial"
#define ICON_TAG 11
#define ICON_WIDTH  50
#define ICON_HEIGHT  50
#define ICON_X   (WIDTH-ICON_WIDTH)/2
#define ICON_Y   (HEIGHT-ICON_HEIGHT)/2


GoldViewMenuItem::GoldViewMenuItem() {
	// TODO Auto-generated constructor stub

}

GoldViewMenuItem::~GoldViewMenuItem() {
	// TODO Auto-generated destructor stub
}

GoldViewMenuItem * GoldViewMenuItem::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
{
    return (GoldViewMenuItem *)MenuItemImage::create(normalImage, selectedImage, disabledImage, callback);
}

void GoldViewMenuItem::setTitle(const std::string& title)
{
	if(getChildByTag(TEXT_TAG)){
		removeChildByTag(TEXT_TAG);
	}
    LabelTTF *label = LabelTTF::create(title, TEXT_FONT_NAME, TEXT_FONT_SIZE);
    label->setAnchorPoint(Point(0, 0));
    label->setPosition((WIDTH-label->getContentSize().width)/2,TEXT_Y);
    label->setColor(Color3B::WHITE);
    addChild(label,1,TEXT_TAG);
}

void GoldViewMenuItem::setIcon(const std::string& iconName)
{
	if(getChildByTag(ICON_TAG)){
		removeChildByTag(ICON_TAG);
	}
	auto icon = Sprite::createWithSpriteFrameName(iconName);
	icon->setAnchorPoint(Vec2::ZERO);
	icon->setPosition(Point(ICON_X,ICON_Y));
	this->addChild(icon,ICON_TAG);
}

Size  GoldViewMenuItem::getSize()
{
    return Size(WIDTH,HEIGHT);
}


